﻿#include "DAAppRibbonArea.h"
#include "AppMainWindow.h"
#include "ui_AppMainWindow.h"
#include "SARibbonBar.h"
#include "SARibbonCategory.h"
#include "SARibbonPannel.h"

DAAppRibbonArea::DAAppRibbonArea(SARibbonMainWindow *w, DACoreInterface *c)
    : DAAppRibbonAreaInterface(w, c)
{
    m_app = qobject_cast<AppMainWindow *>(w);
    ui = m_app->ui;
    buildRibbon();
    //retranslateUi();//不要在构造函数调用虚函数
    setText();
}


void DAAppRibbonArea::retranslateUi()
{
    setText();
}


AppMainWindow *DAAppRibbonArea::app() const
{
    return (m_app);
}


SARibbonBar *DAAppRibbonArea::ribbonBar() const
{
    return (app()->ribbonBar());
}


void DAAppRibbonArea::buildRibbon()
{
    buildMainCategory();
    buildViewCategory();
    ribbonBar()->setRibbonStyle(SARibbonBar::WpsLiteStyleTwoRow);
}


/**
 * @brief 构建主页标签
 */
void DAAppRibbonArea::buildMainCategory()
{
    m_categoryMain = new SARibbonCategory(app());
    m_categoryMain->setObjectName(QStringLiteral("categoryMain"));
    m_pannelMainFileOpt = new SARibbonPannel(m_categoryMain);
    m_pannelMainFileOpt->setObjectName(QStringLiteral("pannelCommon"));
    m_pannelMainFileOpt->addLargeAction(ui->actionOpen);
    m_pannelMainFileOpt->addSmallAction(ui->actionSave);
    m_pannelMainFileOpt->addSmallAction(ui->actionSaveAs);
    m_categoryMain->addPannel(m_pannelMainFileOpt);

    ribbonBar()->addCategoryPage(m_categoryMain);//主页
}


/**
 * @brief 构建视图标签
 */
void DAAppRibbonArea::buildViewCategory()
{
    m_categoryView = new SARibbonCategory(app());
    m_categoryView->setObjectName(QStringLiteral("categoryView"));
    m_pannelViewMainView = new SARibbonPannel(m_categoryView);
    m_pannelViewMainView->setObjectName(QStringLiteral("pannelViewMainView"));
    m_pannelViewMainView->addLargeAction(ui->actionShowWorkFlowArea);
    m_pannelViewMainView->addLargeAction(ui->actionShowChartArea);
    m_pannelViewMainView->addLargeAction(ui->actionShowTableArea);
    m_pannelViewMainView->addSeparator();
    m_pannelViewMainView->addLargeAction(ui->actionShowInfomationWindow);
    m_categoryView->addPannel(m_pannelViewMainView);
    m_pannelViewViewSet = new SARibbonPannel(m_categoryView);
    m_pannelViewViewSet->addLargeAction(ui->actionDefaultView);
    m_categoryView->addPannel(m_pannelViewViewSet);
    ribbonBar()->addCategoryPage(m_categoryView);//视图
}

void DAAppRibbonArea::setText()
{
    ribbonBar()->applicationButton()->setText(tr("File"));          //文件
    m_categoryMain->setCategoryName(tr("Main"));                    //主页
    m_pannelMainFileOpt->setPannelName(tr("File Operation"));       //文件操作
    m_categoryView->setCategoryName(tr("View"));                    //视图
}
